import os
import pymysql

# with open('log/chenwei.log', 'r') as f:
#     log_info = f.readlines()[-1].strip().split('INFO ')[-1]
# print(log_info)
# list_log_info = log_info.split(' ')
# str_date = list_log_info[-2].replace('-', '')[:-2]
# print(list_log_info, str_date)

# for index, mail_info in enumerate(list_log_info):
#     print(index, type(index))


db = pymysql.connect("192.168.50.149","root","root","test",charset='utf8')
cursor = db.cursor()
list_user = ['bixianghong','caoleilei','caolisong','cheguanjia','cheguanjiaem','chenmeng','cuijian','daidanfeng','dangyinqiang','dengchao','duanqian','fangfeihu','fengxiaorui','gaokaijun','guoxufeng','guoyibo','guweixin','hena','hezhengpeng','hr','huangyu','hubingran','huojinfeng','huwei','jenkins','jiangfeng','jiangyoulong','jiangzhang','kangguoxiao','karlzhou','liangxunli','liaowenqiang','libin','lihongyang','lijiazhang','lijinming','lijunjie','lipeizhao','lipeng','liuchang','liudan','liufei','liuhong','liujinxiong','liujun1','liujun','liuliugen','liuming','liusen','liuzhitie','liuzhou','liuzongxuan','lixiaohua','liyufei','longshigao','lucewu','luoyuyang','luxi','lvguanjiao','mabiao','mashuaijuan','mawennan','mengxianjun','niuyin','oulingyan','panliuhua','panshengyu','pengdong','pengqingfeng','pengshanzhen','pupengfei','qianweihong','qianxiang','qifengliang','shengruixuan','shenzhou','shigaohong','shiyiling','shuxuan','sunchao','sunfukui','sunkai','sunmeichen','suntao','sunxiaojun','sunzhongshuai','tangxuewen','tankesong','tianhongjun','tianshoubao','tracywang','wangdong','wangjinliang','wangqingfeng','wangsai','wangxinglin','wangyue','wangyulan','wangzhaojun','wangzhen','wangzhentao','wangzhenya','wangzhigang','weixiaodong','wenjiajun','wenpengcheng','wubin','wucui','wuhao','wuji','wulijun','xiaoyao','xujian','xule','xulingxiao','xuxiaoming','xuzhenghao','yangchao','yanghailin','yangzhengguang','yanyidan','yaoguang','yaoshaojun','yingyang','yonghao','yuanxuemin','yuezhenya','yulong','yuyang','yuyunjie','zengchunwei','zhaiwenhua','zhaiyangbin','zhanghaiyu','zhangkezhen','zhangwei','zhangxianfa','zhangxiangxiang','zhangyanling','zhangyin','zhangzhilu','zhaogongping','zhaohuiqin','zhaolei','zhaolonggang','zhaopin','zhaoyudong','zhengfei','zhenglushui','zhoubaoguo','zhouchuya','zhoujiamin','zhouzhe','zhouzhen','zhuxiaofen','zhuyueping','zhuzhiqiang','zoufangyu','zouya']


# cursor.execute('SELECT username,str_id,str_time,last_time,crawling FROM user where complete=0')
# tuple_userinfo = cursor.fetchall()
# for username, str_id, str_time, last_time, crawling in tuple_userinfo:
#     print(username, str_id, str_time, last_time, crawling)
#     print(type(username),type(str_id),type(str_time),type(last_time),type(crawling))


# cursor.execute('SELECT username,str_id,str_time,last_time FROM user where complete!=0')
# tuple_userinfo = cursor.fetchall()
# username = 'chenwei'
complete = '0'
str_id = ''
str_time = ''
last_time = '2020040910'
crawling = '0'

# for username in list_user:
#     insert_sql = 'INSERT INTO user VALUES ("%s", "%s", "%s", "%s", "%s", "%s")'%(username,complete,str_id,str_time,last_time, crawling)
#     cursor.execute(insert_sql)
#     db.commit()
# update_sql = 'INSERT INTO user1 VALUES ("%s", "%s", "%s", "%s", "%s", "%s")'%('hr',complete,str_id,str_time,last_time, crawling)
# update_sql = 'update user set str_id="%s",str_time="%s" where username="%s"'%('__p8_mail_af6f2e7bb3f7f05ff52a00fc62842aa3_time' , '201901' ,'chenwei')
# update_sql = 'update user set crawling="%s" where username="%s"'%('0' ,'chenwei')

# update_sql = 'update user set last_time="%s" where username="%s"'%('2020040911' ,'chenwei')
# update_sql = 'update user1 set last_time="2020040910", str_id="__p8_mail_12734c0c240e3292e2c9f8d3a24aec69_time",str_time="201902",crawling=0 where username="karlzhou"'
update_sql = 'update user1 set complete=0  where username="karlzhou"'
# update_sql = 'update user1 set crawling=0, complete=0, last_time="2020050801" where username="yuyang" or username="yanghailin" '
# update_sql = 'update user1 set crawling=0, complete=0, str_id="__p8_mail_f6449aa38331f6dae2dac86fe3b56d49_time" where username="yaoshaojun" '

# update_sql = 'update user1 set crawling=0 where username!="zhaopin"'
# update_sql = 'update user set str_id="",str_time="" where last_time="2020040910"'
# update_sql = 'update user1 set str_id="",str_time="" where username="caoleilei" or username="caolisong" or username="chenmeng" or username="cuijian" \
# or username="dangyinqiang" or username="gaokaijun" '
# update_sql = 'delete from user1 where username="hr" or username="tracywang" or username="lijiazhang"'
# update_sql = 'update user1 set str_id="__p8_mail_ebc3505f46c0d3f5f3a6a2d4aaae37d6_time" where username="hena"'
# update_sql = 'update user1 set str_id="",str_time="",crawling=0,last_time="2020040910" where username="wangzhenya"'
# update_sql = 'update user set last_time="2020040910" where crawling="%s"'%'0'

# update_sql = 'delete from user where username="tankesong"'

# # update_sql = 'update user set complete="%s" where username="%s"'%('0' ,'chenwei')

# update_sql = "update test.user1 set crawling=0,complete=0,str_id='',str_time='',last_time='2020040910' where username!=''"


# insert_sql = 'INSERT INTO user1 VALUES ("%s", "%s", "%s", "%s", "%s", "%s")'%('tracywang','0','','','2020040910', '0')
# insert_sql = 'delete from user1 where username="tracywang" and str_time=""'
# cursor.execute(insert_sql)
# db.commit()


cursor.execute(update_sql)

db.commit()
cursor.close()
db.close()